home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / threads / timer.c < prev    next >
C/C++ Source or Header  |  1996-02-04  |  1KB  |  99 lines

  1.  
  2.  
  3. /*
  4.  *
  5.  *    Copyright (c) 1993-1996 Algorithms Corporation
  6.  *    3020 Liberty Hills Drive
  7.  *    Franklin, TN  37067
  8.  *
  9.  *    ALL RIGHTS RESERVED.
  10.  *
  11.  *
  12.  *
  13.  */
  14.  
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <dos.h>
  19. #include <stdlib.h>
  20.  
  21. #pragma check_stack( off )
  22. #pragma check_pointer( off )
  23.  
  24. #define TICKPERMIN  1092L
  25. #define MINPERHOUR  60L
  26.  
  27. #define __interrupt _interrupt
  28. #define __far _far
  29.  
  30. static    void (__interrupt __far *oldtimer)();
  31. static    void __interrupt __far newtimer();
  32.  
  33.  
  34. #ifdef    __cplusplus
  35. extern "C"  {
  36. #endif
  37. #ifdef TEST
  38. int    _tick_count=10000;
  39. #else
  40. extern    int    _tick_count;
  41. #endif
  42. #ifdef    __cplusplus
  43. }
  44. #endif
  45.  
  46. static    void    _end_timer(void)
  47. {
  48.     _dos_setvect( 0x1c, oldtimer );
  49. }
  50.  
  51. void    _start_timer(void)
  52. {
  53.     oldtimer = _dos_getvect( (unsigned)0x1c );
  54.     _dos_setvect( 0x1c, newtimer );
  55.     atexit( _end_timer );
  56. }
  57.  
  58. static    void __interrupt __far newtimer(void)
  59. {
  60.     if (_tick_count)
  61.         _tick_count--;
  62.         _chain_intr( oldtimer );
  63. }
  64.  
  65.  
  66. #ifdef TEST
  67.  
  68. main()
  69. {
  70.     int    n;
  71.     long    i;
  72.  
  73.     _start_timer();
  74.  
  75.     for (n=0 ; n++ != 10 ; )  {
  76.         fprintf(stderr, "Timer = %d\n", _tick_count);
  77.         for (i=0L ; i++ != 1000000L ; );
  78.     }
  79.     return(0);
  80. }
  81.  
  82. #endif
  83.  
  84.  
  85.  
  86. /*
  87.  *
  88.  *    Copyright (c) 1993-1996 Algorithms Corporation
  89.  *    3020 Liberty Hills Drive
  90.  *    Franklin, TN  37067
  91.  *
  92.  *    ALL RIGHTS RESERVED.
  93.  *
  94.  *
  95.  *
  96.  */
  97.  
  98.  
  99.